﻿using System;
using System.Collections.Generic;
using DeepEarth.Map.Core;
using System.Linq;
using DeepEarth.Map.Core.Tiling;

namespace DeepEarth.Map.TileSources
{
    public class XYZTileSourceFactory : BaseTileSourceFactory
    {

        public readonly static MapMode XYZ = new MapMode("xyz", "xyz", "XYZ", "XYZ", 0, false, true, true);

        private static readonly MapMode[] _availableModes = new[] { XYZ };
        public override IList<MapMode> AvailableModes { get { return _availableModes; } }

		private readonly XYZTileSource XYZTileSource = new XYZTileSource();

        public static bool IsValidMode(MapMode mode)
		{
			return _availableModes.Contains(mode);
		}

        public static void ValidateMode(MapMode mode)
		{
			if (!IsValidMode(mode))
				throw new ArgumentOutOfRangeException(String.Format("Map mode '{0}:{1}' is not valid for the XYZ provider",
																	mode.ProviderKey,
																	mode.Identifier));
		}


        public override BaseTileSource CreateTileSource(MapMode mode)
		{
			mode = ValidateAndCoerceMapMode(mode);
			if (mode == XYZ)
				return XYZTileSource;

			throw new NotImplementedException("A provider for the mode '" + mode.Name + "' is not implemented.");
		}
	}
}
